package com.huli.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huli.domain.Carport;
import com.huli.param.CarportParam;
import com.huli.service.CarportService;
import com.huli.utils.Result;
import com.huli.vo.CarportVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("carport")
@Api(tags = "车位服务")
public class CarportController {

    @Autowired
    private CarportService carportService;

    /**
     * 根据车位ID选择车位
     * @param carportId
     * @return
     */
    @ApiOperation("根据车位ID选择车位")
    @ApiImplicitParam(name = "carportId", value = "车位ID", required = true, paramType = "query")
    @GetMapping("selectCarportById")
    public Result selectCarportById(Integer carportId) {
        if (carportId != null) {
            Carport carport = carportService.getById(carportId);
            return Result.successResult(carport);
        } else {
            return Result.failedResult(400, "你传的啥玩意儿");
        }
    }

    /**
     * @param carportId
     * @return
     */
    @ApiOperation("根据车位ID查询车库信息")
    @ApiImplicitParam(name = "carportId", value = "车位Id", required = true)
    @GetMapping("selectGarage")
    public Result selectGarage(Integer carportId) {
        Carport carport = (Carport) selectCarportById(carportId).getData();
        return Result.successResult(carportService.selectGarageByCarportId(carport.getGarageId()));
    }

    /**
     * 修改车位状态接口
     */
    @ApiOperation("修改车位状态")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "carportId", value = "车位Id", required = true, paramType = "query"),
        @ApiImplicitParam(name = "carportStatus", value = "车位状态", required = true, paramType = "query")
    })
    @PutMapping("updateCarportStatus")
    public Result updateCarportStatus(CarportParam carportParam) {
        if (carportParam != null) {
            Carport carport = carportService.updateCarportStatusByCarportId(carportParam);
            if (carport != null) {
                return Result.successResult(carport);
            } else {
                return Result.failedResult(500, "服务器错误");
            }
        } else {
            return Result.failedResult(400, "你的问题");
        }
    }


    /**
     * 查询所有车位
     * 还可根据车库ID查询车库所有车位
     */
    @ApiOperation("查询所有车位")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "garageId", value = "车库Id", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "页码", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "个数", required = true, paramType = "query")
    })
    @GetMapping("selectAllCarport")
    public Result selectAllCarport(CarportParam carportParam) {

        IPage<CarportVo> carportVoIPage = carportService.selectAllCarports(carportParam);

        return Result.successResult(carportVoIPage);
    }

    /**
     * 查询附近车库
     * @param carportParam
     * @return
     */
    @ApiOperation("根据自身位置,查询自身附近车库")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "latitudeAndLongitude", value = "经纬度", required = true, paramType = "query"),
            @ApiImplicitParam(name = "distance", value = "范围", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "页码", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "显示条数", required = true, paramType = "query"),
    })
    @GetMapping("selectNearCarport")
    public Result selectNearCarport(CarportParam carportParam) {
        return Result.successResult(carportService.selectNearGarage(carportParam));

    }
}



